<template>
    <l-dialog
        :title="title"

        :visible.sync="midVisible"
        :hasBtns="false"

        width="424px"
        :height="280"
        @close="closeDialog"
        @opened="handleOpened"
        @ok="okDialog"
        >
        <div class="l-rblock" style="padding:8px 32px 0 32px;overflow: auto;" >
            <el-upload
                drag
                action
                :http-request="myChunkedUpload"
                multiple
                ref="myupload"
                accept=".db"

                :data="param"
                >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>
        </div>
    </l-dialog>
</template>

<script>
import chunkedUpload from '../../../../util/chunkedUpload'
export default {
    name:'l-db-import',
    props: {
        dbCode:String,
        projectId:String,
        isUpdateData:Boolean,
        visible:{
            type:Boolean,
            default:false
        }
    },
    data () {
        return {
            folderId:''
        };
    },
    created () {
        this.folderId = this.$uuid();
    },
    mounted () {
    },
    computed:{
        midVisible:{
            get(){
                return this.visible;
            },
            set(val){
                this.$emit('update:visible',val);
            }
        },
        param(){
            return {
                folderId: this.folderId
            };
        },
        title(){
            if(this.isUpdateData){
                return '导入库(结构+数据)'
            }
            else{
                return '导入库(结构)'
            }
        }
    },
    methods:{
        closeDialog() {
            this.$refs.myupload.clearFiles
        },
        handleOpened(){
        },
        okDialog(){
            this.midVisible =false;
        },
        myChunkedUpload(option){
            chunkedUpload(option,(data)=>{
                const api = window.$api.data.codeTable
                data.isUpdateData = this.isUpdateData
                return api.uploadEx(this.dbCode,data,this.projectId)
            })
        }
    }
}
</script>
